/********************************** (C) COPYRIGHT
 ******************************** File Name          : iap.c Author : WCH
 * Version            : V1.0.0
 * Date               : 2022/11/21
 * Description        : CH32V003  fast program
 *******************************************************************************
 * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
 * Attention: This software (modified or not) and binary are used for
 * microcontroller manufactured by Nanjing Qinheng Microelectronics.
 *******************************************************************************/

#include "flash.h"

void flash_save_parameters(uint16_t *data)
{
    FLASH_ROM_ERASE(FLASH_SAVE_ADDR, FLASH_SAVE_LEN);
    FLASH_ROM_WRITE(FLASH_SAVE_ADDR, (uint32_t *)data, FLASH_SAVE_LEN);
}

void flash_load_parameters(uint16_t *data)
{
    __IO uint16_t *p = (__IO uint16_t *)FLASH_SAVE_ADDR;
    __IO uint16_t *end = (__IO uint16_t *)(FLASH_SAVE_ADDR + FLASH_SAVE_LEN);
    while (p < end)
    {
        *data++ = *p++;
    }
}
